from math import *
from util import *

# 几何常数
h = 0.018
r_move_out_t = r_move_in_p = 0.05
r_move_in_t = r_move_out_p = 0.12
r_stat_out_t = r_stat_in_p = 0.128
r_stat_in_t = r_stat_out_p = 0.185

# 物性常数
rou = 1.225

# 设计常数
n = 3300
mt = 0.12  # 涡轮流量
mp = 0.15  # 初设压气机流量
P = 150  # 涡轮输出功
tao_stat_p = 2.5
tao_stat_t = 2.1

w = n / 60 * 2 * pi


def cr(r, m):
    return m / 2 / pi / rou / r / h


c1u_p = 0  # 压气机进口周向速度为0
c1r_p = cr(r_move_in_p, mp)  # 压气机入口径向速度
c2r_p = cr(r_move_out_p, mp)  # 压气机转子出口径向速度

# Lu=w*(r2*c2u-r1*c1u)=w*r2*c2u
Lu = P / mp  # 压气机轮缘功
c2u_p_real = Lu / w / r_move_out_p  # 压气机周向速度(实际)
u2 = w * r_move_out_p  # 转子出口速度
u1 = w * r_move_in_p
# sigma=1-(c2u_design-c2u_real)/u2

beta2_p=45*pi/180
N_move_t=10
for i in range(10):
    sigma = 1-(cos(beta2_p))**0.5/N_move_t**0.7  # 滑移因子
    print("sigma",sigma)
    c2u_p_dsign = u2 * (1 - sigma) + c2u_p_real  # 设计转子出口周向速度
    # print(c2u_p_real, c2u_p_dsign, c2r_p, u2)  # u2比c2u大，说明是后弯
    tanb2_p = (c2u_p_dsign - u2) / c2r_p  # 压气机出口气流角（绝对，前弯为正
    beta2_p = atan(tanb2_p)

beta1_p = atan(c1u_p - u1) / c1r_p  # 进口相对气流角
beta_mid_p = (beta2_p + beta1_p) / 2  # 进出口平均气流角
r_move_mid_p = (r_move_in_p + r_move_out_p) / 2  # 转子平均半径
cr_mid_p = cr(r_move_mid_p, mp)  # 平均半径处径向速度
wavg = cr_mid_p / cos(beta_mid_p)  # 平均半径处相对速度

print("压气机转子出口相对气流角：", beta2_p * 180 / pi, " 压气机转子进口相对气流角：", beta1_p * 180 / pi)

Nb_p_lim = mp / (2 * rou * wavg ** 2 * r_move_mid_p * h) * (r_move_out_p * c2u_p_real - r_move_in_p * c1u_p) / (
        r_move_out_p - r_move_in_p)  # 叶片数量下限

print("压气机转子叶片数量下限为", Nb_p_lim)
print("压气机转子叶片数",N_move_t)
# print(sigma*u2**2*mp+u2*tanb2_p/2/r_move_out_p/pi/rou/h*mp**2)

# 压气机进出口相对速度
w1_p=c1r_p/cos(beta1_p)
w2_p=c2r_p/cos(beta2_p)
print("压气机转子进口速度",w1_p,"压气机转子出口速度",w2_p)

# 使用圆弧叶片
Rc_move_p, R0_move_p = angle2R(beta1_p, beta2_p, r_move_in_p, r_move_out_p)

print("压气机转子圆弧半径", Rc_move_p, " 压气机转子圆心半径", R0_move_p)

# 压气机扩压器
# 首先计算进口径向速度
c3r_p = cr(r_stat_in_p, mp)
c3u_p = r_move_out_p * c2u_p_real / r_stat_in_p

beta3_p = atan(c3u_p / c3r_p)
print("压气机静子进口几何角", beta3_p * 180 / pi)
beta4_p = beta3_p - 15 * pi / 180  #
print("压气机静子出口几何角", beta4_p * 180 / pi)

Rc_stat_p, R0_stat_p = angle2R(beta3_p, beta4_p, r_stat_in_p, r_stat_out_p)
print("压气机静子圆弧半径", Rc_stat_p, " 压气机静子圆心半径", R0_stat_p)

l = (r_stat_out_p - r_stat_in_p) / cos((beta3_p + beta4_p) / 2)
t = l / tao_stat_p  # 栅距
N_stat_p = 2 * pi * r_stat_in_p / t
print("压气机静子数", N_stat_p)  # 取22？
# 扩压器当量扩张角
theta=2*atan((sqrt(2*r_stat_out_p*h*cos(beta4_p))-sqrt(2*r_stat_in_p*h*cos(beta3_p)))/sqrt(N_stat_p)/l)
print("扩压器当量扩张角",theta*180/pi)
# 压气机总压升
dp_p=rou*P/mp*0.8
print("压气机总压升",dp_p)

# 涡轮转子叶片
c4u_t = 0  # 涡轮转子出口周向无速度
c3u_t = mp * r_move_out_p * c2u_p_real / (mt * r_move_in_t)

# print(c3u_t)
u3 = w * r_move_out_t
u4 = w * r_move_in_t
c3r_t = cr(r_move_in_t, mt)
c4r_t = cr(r_move_out_t, mt)
beta3_t = atan(c3u_t - u3) / c3r_t
beta4_t = atan(-u4 / c4r_t)
print("涡轮转子进口几何角", beta3_t, "涡轮转子出口几何角", beta4_t)

beta_mid_t = (beta4_t + beta3_t) / 2
# print(beta4_t, beta3_t)
r_move_mid_t = (r_move_in_t + r_move_out_t) / 2
cr_mid_t = cr(r_move_mid_t, mp)
wavg_t = cr_mid_t / cos(beta_mid_t)
Nb_t_lim = mp / (2 * rou * wavg_t ** 2 * r_move_mid_t * h) * (r_move_out_t * c3u_t - r_move_in_t * c4u_t) / (
        r_move_out_t - r_move_in_t)

print("涡轮转子叶片数下限", abs(Nb_t_lim))
print("涡轮转子叶片数", 8)

N_move_t = 2 * pi * r_move_out_t * cos(beta4_t) / 0.01
print("涡轮转子叶片数", N_move_t)

# 涡轮静子
c2r_t = cr(r_stat_out_t, mt)
c1r_t = cr(r_stat_in_t, mt)
c2u_t = c3u_t * r_move_in_t / r_stat_out_t
c1u_t = 0

beta1_t = 0
beta2_t = atan(c2u_t / c2r_t)

print("涡轮静子进口几何角", beta1_t, "涡轮静子出口几何角", beta2_t * 180 / pi)
l = (r_stat_in_t - r_stat_out_t) / cos((beta1_t + beta2_t) / 2)
t = l *0.75  # 栅距
N_stat_t = 2 * pi * r_stat_in_t / t
print("涡轮静子数", N_stat_t)  # 取22？

# 校核涡轮压降
dp_t=P/mt*rou/0.7
print("涡轮压降",dp_t)


